﻿package net.wangit.dev.wizard.unit;

import net.wangit.dev.wizard.WizardUtil;
import net.wangit.framework.config.WizardSettings;
import net.wangit.jdbc.ColumnRow;
import net.wangit.jdbc.DB;
import net.wangit.jdbc.Table;
import net.wangit.util.Checker;

public class AListUnit {

	public AListUnit() {
	}

	public static final void create(DB db, String domain, String groupId,
			String unitId, String unitName, String tableName,
			String queryUnitId, String sql, boolean editAble, int accessible,
			boolean pageNavigator, String parentUnitId) throws Exception {
		Table table = new Table("dev", "UNIT");
		ColumnRow cRow = table.addInsertRow();
		cRow.set("uid", unitId);
		cRow.set("gid", groupId);
		cRow.set("c", 2);
		cRow.set("ti", unitName);
		cRow.set("st", 1);
		cRow.set("co", 0);
		cRow.set("lqu", queryUnitId);
		cRow.set("t", tableName);
		if (Checker.isEmpty(sql))
			sql = WizardUtil.getListUnitSql(tableName);
		cRow.set("dm", 1);
		cRow.set("de", sql);
		cRow.set("li", "1");
		cRow.set("ln", "1");
		cRow.set("lsm", 1);
		if (!Checker.isEmpty(parentUnitId))
			cRow.set("pid", parentUnitId);
		cRow.set("ub", WizardSettings.instance().getListShowUnitBorder());
		cRow.set("tb", WizardSettings.instance().getListShowTitleBorder());
		cRow.set("gb", WizardSettings.instance().getListShowGridBorder());
		cRow.set("cb", WizardSettings.instance().getListShowCellBorder());
		cRow.set("pp", accessible);
		cRow.set("au", accessible);
		if (!pageNavigator)
			cRow.set("ls", 0);
		cRow.set("ms", "1");
		if (editAble) {
			cRow.set("ais", "1");
			cRow.set("ma", "1");
			cRow.set("me", "1");
		} else {
			cRow.set("ma", "0");
			cRow.set("me", "0");
		}
		cRow.set("l", "0");
		cRow.set("y", "0");
		db.save(table);
	}
}
